Page({
    data: {
        tempFilePath: ""
    },
    async upload() {
        let imageRes = await wx.chooseMedia({
            mediaType: "image"
        })
        // 获取图片
        let imagePath = imageRes.tempFiles[0].tempFilePath;

        let timeStamp = new Date().getTime();
        let extension = imagePath.split(".").pop()
        let imgName = `${timeStamp}.${extension}`

        let res = await wx.cloud.uploadFile({
            filePath: imagePath,
            cloudPath: "malu/" + imgName
        })
        console.log("res:", res);
    },
    async download() {
        let res = await wx.cloud.downloadFile({
            fileID: "cloud://malu-9gjr8vrn08c2dfb4.6d61-malu-9gjr8vrn08c2dfb4-1316272586/malu/1678349868731.png"
        })
        // res里面保存了，把资源下载到什么地方了
        // console.log("res:", res.tempFilePath);
        this.setData({
            tempFilePath: res.tempFilePath
        })
    },
    async delete() {
        let res = await wx.cloud.deleteFile({
            fileList: [
                "cloud://malu-9gjr8vrn08c2dfb4.6d61-malu-9gjr8vrn08c2dfb4-1316272586/malu/1678349868731.png"
            ]
        })
        console.log(res);
    },
    async tempFile() {
        let res = await wx.cloud.getTempFileURL({
            fileList: [
                "cloud://malu-9gjr8vrn08c2dfb4.6d61-malu-9gjr8vrn08c2dfb4-1316272586/malu/1678350128958.png"
            ]
        })
        console.log(res);
    }
})